import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
import timezone from "dayjs/plugin/timezone";

dayjs.extend(utc);
dayjs.extend(timezone);

/** 时间相关 */
export class Time {
   /** 获取东八区当前时间 */
   static Now() {
      // 获取本地时间
      let nowDate = new Date(dayjs().utc().valueOf() + 8 * 60 * 60 * 1000);
      return nowDate;
   }

   /** 格式化时间 */
   static Format(time: number | Date | string | null, formatString = "YYYY-MM-DD HH:mm:ss") {
      try {
         if (!!time) {
            return dayjs(time).utc().format(formatString);
         } else {
            return null;
         }
      } catch (error) {
         return null;
      }
   }
}
